/*
 * stm32_jy901.c
 *
 *  Created on: 2015年8月12日
 *      Author: fc
 */

#include "stm32_jy901.h"
Jy901Struct jy901_struct;

void stm32_jy901_init(){
	stm32_usart2_init();
}

Jy901Struct* stm32_jy901_get(){
	static uint8_t c=0,s_c=0,H,L,buff[6];
	static int16_t val;
	while(1){
		c = stm32_usart2_read();
		if(s_c == 0x55&&(c==0x53||c==0x52)){//Angle
			break;
		}
		s_c = c;
	}
	if(c == 0x53){
		L = stm32_usart2_read();
		H = stm32_usart2_read();
		val = L;
		val |= H<<8;
		jy901_struct.angle.x = val;
		L = stm32_usart2_read();
		H = stm32_usart2_read();
		val = L;
		val |= H<<8;
		jy901_struct.angle.y = val;
		L = stm32_usart2_read();
		H = stm32_usart2_read();
		val = L;
		val |= H<<8;
		jy901_struct.angle.z = val;
	}
	if(c == 0x52){
		L = stm32_usart2_read();
		H = stm32_usart2_read();
		val = L;
		val |= H<<8;
		jy901_struct.speed.x = val;
		L = stm32_usart2_read();
		H = stm32_usart2_read();
		val = L;
		val |= H<<8;
		jy901_struct.speed.y = val;
		L = stm32_usart2_read();
		H = stm32_usart2_read();
		val = L;
		val |= H<<8;
		jy901_struct.speed.z = val;
	}
	return &jy901_struct;
}
